package design.mode.effective_java.chapter2.item2.pizza;

import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author mingde
 * @date 2021/8/2 22:48
 * @describe 抽象类有抽象类构建器；具体类有具体类构建器。
 * 例如，考虑一个在层次结构处于最低端的抽象类，它代表各种比萨饼：
 */
public abstract class Pizza {
    public enum Topping {HAM, MUSHROOM, ONION, PEPPER, SAUSAGE}

    final Set<Topping> toppings;

    abstract static class Builder<T extends Builder<T>> {
        EnumSet<Topping> toppings = EnumSet.noneOf(Topping.class);

        public T addToppings(Topping topping) {
            toppings.add(Objects.requireNonNull(topping));
            return self();
        }

        abstract Pizza build();

        protected abstract T self();
    }

    Pizza(Builder<?> builder) {
        toppings = builder.toppings.clone();
    }


    // Pizza.Builder 是具有递归类型参数的泛型类型（

}
